<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Stack {
            constructor() {
                this.item = [];
            }
            push(element) {
                this.item.push(element);
            }
            pop() {
                return this.item.pop();
            }
            peek() {
                return this.item[this.item.length - 1];
            }
            isEmpty() {
                return this.item.length === 0;
            }
            clear() {
                this.item = [];
            }
            size() {
                return this.item.length;
            }
            toString() {
                return this.item.toString();
            }
        }

        function decimal2Binary(decNumber) {
            //const stack = new Stack();
            let number = decNumber; //商
            let rem; //余数
            let binaryString = '';
            const remstack = new Stack();
            while (number > 0) {
                number / 2;
                rem = Math.floor(number % 2);
                number = Math.floor(number / 2);
                remstack.push(rem);
            }
            while (!remstack.isEmpty()) {
                binaryString += remstack.pop().toString();
            }
            return binaryString;
        }
        document.write(decimal2Binary(15));
        //Array
        //let array=new Array();
        //初始化一个栈
        // const stack = new Stack();
        // stack.push(1);
        // stack.push(2);
        // stack.push(3);
        // document.write(stack.item);
        // stack.pop();
        // document.write("</br>");
        // document.write(stack.item);
        // document.write("</br>");
        // document.write(stack.peek());
        // document.write("</br>");
        // document.write(stack.isEmpty());
        // document.write("</br>");
        // document.write(stack.size());
        // document.write("</br>");
        // document.write("</br>");
        // console.log(stack.item);
        // console.log(stack.pop());
        // console.log(stack.item);
    </script>
</body>

</html>